<template>
	<view :data-theme="theme">
		<view class='integral-details'>
			<view class='header'>
				<view class='currentScore'>当前消费积分</view>
				<view class="scoreNum">{{ promotionInfo.brokeragePrice || 0 }}</view>
				<view class='line'></view>
				<view class='nav acea-row'>
					<view class='item'>
						<!-- <view class='num'>{{integral.settledIntegral||0}}</view> -->
						<view>累计消费积分</view>
					</view>
					<view class='item'>
						<view class='num'>{{ promotionInfo.settledCommissionPrice ?
							Number(promotionInfo.settledCommissionPrice).toFixed(2) : 0}}
						</view>
						<view>已使用消费积分</view>
					</view>
					<view class='item'>
						<view class='num'>{{ promotionInfo.freezePrice ? Number(promotionInfo.freezePrice).toFixed(2) :
							0}}</view>
						<view>冻结消费积分</view>
					</view>
				</view>
			</view>
			<view class='wrapper'>
				<view class='nav acea-row'>
					<view class='item acea-row row-center-wrapper' :class='current == index ? "on" : ""'
						v-for="(item, index) in navList" :key='index' @click='nav(index)'><text class='iconfont'
							:class="item.icon"></text>{{ item.name }}</view>
				</view>
				<view class='list' :hidden='current != 0'>
					<view v-for="(item, index) in recordList" :key="index">
						<view class='data'>{{ item.month }}</view>
						<view class='item acea-row row-between-wrapper' v-for="(child, indexn) in item.list"
							:key="indexn">
							<view>
								<view class='state'>{{ child.title }}</view>
								<view>{{ child.updateTime }}</view>
							</view>
							<view class='num font_color' v-if="child.type === 1">+{{ child.price }}</view>
							<view class='num' v-else>-{{ child.price }}</view>

						</view>
					</view>
					<view class='loadingicon acea-row row-center-wrapper' v-if="recordList.length > 0">
						<text class='loading iconfont icon-jiazai' :hidden='loading == false'></text>{{ loadTitle }}
					</view>
					<view class='noCart' v-if="recordList.length == 0">
						<view class='pictrue'>
							<image :src="urlDomain + 'crmebimage/presets/noJilu.png'"></image>
							<view class="default_txt">暂无贡献值记录哦~</view>
						</view>
					</view>
				</view>
				<view class='list' :hidden='current != 1'>
					<view v-for="(item, index) in userBillList" :key="index">
						<view class='data'>{{ item.month }}</view>
						<view class='item acea-row row-between-wrapper' v-for="(child, indexn) in item.list"
							:key="indexn">
							<view>
								<view class='state'>{{ child.type == 1 ? '订单退款': '购买商品' }}</view>
								<view>{{ child.createTime }}</view>
								<view>订单:{{ child.linkId }}</view>
							</view>
							<view class='num font_color' v-if="child.type === 1">+{{ child.amount }}</view>
							<view class='num' v-else>-{{ child.amount }}</view>

						</view>
						<!-- <view class="remark">说明：{{child.remark}}</view> -->
					</view>
					<view class='loadingicon acea-row row-center-wrapper' v-if="userBillList.length > 0">
						<text class='loading iconfont icon-jiazai' :hidden='loading == false'></text>{{ loadTitle }}
					</view>
					<view class='noCart' v-if="userBillList.length == 0">
						<view class='pictrue'>
							<image :src="urlDomain + 'crmebimage/presets/noJilu.png'"></image>
							<view class="default_txt">暂无贡献值记录哦~</view>
						</view>
					</view>
				</view>
				<view class='list' :hidden='current != 2'>
					<view v-for="(item, index) in recordList" :key="index">
						<view class='data'>{{ item.month }}</view>
						<view class='item acea-row row-between-wrapper' v-for="(child, indexn) in item.list"
							:key="indexn">
							<view>
								<view class='state'>冻结佣金</view>
								<view class='state'>{{ child.title }}</view>
								<view>{{ child.updateTime }}</view>
							</view>
							<view class='num font_color' v-if="child.type === 1">+{{ child.price }}</view>
							<view class='num' v-else>-{{ child.price }}</view>
				
						</view>
					</view>
					<view class='loadingicon acea-row row-center-wrapper' v-if="recordList.length > 0">
						<text class='loading iconfont icon-jiazai' :hidden='loading == false'></text>{{ loadTitle }}
					</view>
					<view class='noCart' v-if="recordList.length == 0">
						<view class='pictrue'>
							<image :src="urlDomain + 'crmebimage/presets/noJilu.png'"></image>
							<view class="default_txt">暂无贡献值记录哦~</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
import { postIntegralUser, getBrokeragelList, myPromotion, getCommissionInfo, getBillList } from '@/api/user.js';
import {
	toLogin
} from '@/libs/login.js';
import {
	mapGetters
} from "vuex";
let app = getApp();
export default {
	data() {
		return {
			urlDomain: this.$Cache.get("imgHost"),
			navList: [{
				'name': '获得明细',
				'icon': 'icon-mingxi'
			},
			{
				'name': '消费明细',
				'icon': 'icon-tishengfenzhi'
			},
			{
				'name': '冻结明细',
				'icon': 'icon-tishengfenzhi'
			}
			],
			current: 0,
			page: 1,
			limit: 10,
			recordList: [],
			integral: {},
			loadend: false,
			loading: false,
			loadTitle: '加载更多',
			theme: app.globalData.theme,
			promotionInfo: {},
			type: '3',
			userBillList: [],
		};
	},
	computed: mapGetters(['isLogin', 'type']),
	watch: {
		isLogin: {
			handler: function (newV, oldV) {
				if (newV) {
					this.getUserInfo();
					this.getBrokeragelList();
				}
			},
			deep: true
		},
		type: {
			handler: function (newV, oldV) {
				this.recordList = []
				this.loadend = false
			},
			deep: true
		},
	},
	onLoad() {
		if (this.isLogin) {
			this.getUserInfo();
			this.getBrokeragelList();
			this.getUserBillList();
		} else {
			toLogin();
		}
	},
	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {
    if (this.current == 1){
      this.getUserBillList()
    }else{
      this.getBrokeragelList();
    }
	},
	methods: {
		getUserInfo: function () {
			let that = this;
			myPromotion().then(res => {
				that.$set(that, 'promotionInfo', res.data);
			});
		},
		/**
		 * 获取消费明细
		 */
		getUserBillList: function () {
			let that = this;
			if (that.loadend) return;
			that.loading = true;
			that.loadTitle = "";
			let data = {
				page: that.page,
				limit: that.limit,
				type: 'expenditure'
			}
			getBillList(data).then(function (res) {
				let list = res.data.list ? res.data.list : [],
					loadend = res.data.totalPage <= that.page;
				for (let i = 0; i < list.length; i++) {
					let time1 = list[i].month;
					let array1 = list[i].list;
					let isEquals = false;
					for (let j = 0; j < that.userBillList.length; j++) {
						let time2 = that.userBillList[j].month;
						let array2 = that.userBillList[j].list;
						if (time1 == time2) {
							array2.push.apply(array2, array1);
							that.userBillList[j].list = array2;
							isEquals = true;
							break;
						}
					}
					if (!isEquals) {
						that.userBillList.push({
							month: time1,
							list: array1
						})
					}
				}
				that.$set(that, 'userBillList', that.userBillList);
				that.page += 1;
				that.loadend = loadend;
				that.loadTitle = loadend ? "哼??~我也是有底线的~" : "加载更多";
				that.loading = false;
			}, function (res) {
				that.loadTitle = '加载更多';
				that.loading = false;
			});
		},

		/**
		 * 获取积分明细   status 3 获得明细   2冻结明细
		 */
		getBrokeragelList: function () {
			console.log(this.loadend, 'loadend--这个地方会根据返回的数据来决定是否还会再发请求');
			let that = this;
			let page = that.page;
			let limit = that.limit;
			let loadend = that.loadend;
			let recordType = that.type;
			let recordList = that.recordList;
			let recordListNew = [];
			if (loadend == true) return;
			getCommissionInfo({
				page: page,
				limit: limit,
				status: recordType,
			}).then(res => {
				console.log(res, '111');
				if (res.data.list) {
					console.log(res.data.list, '数据存在')
					that.page = page + 1;
					let len = that.page > res.data.totalPage;
					let recordListData = res.data.list || [];
					
					recordListNew = recordList.concat(recordListData);
					that.loadend = len;
					
					that.$set(that, 'recordList', recordListNew);
					console.log(that.recordList,"数组数据")
				}
			}).catch((err) => {
				console.log(err, 'catch err');
			});
		},
		nav: function (current) {
			console.log(current);
			this.current = current;
			this.page=1
			if (current == 0) {
				this.loadend =false
				this.recordList = []
				this.type = '3'
				this.getBrokeragelList();
			}
			if (current == 1) {
				this.loadend =false
				// this.recordList = []
				// this.type = '1'
				// this.getBrokeragelList();
        this.$set(this, 'userBillList', []);
        this.getUserBillList()
			}
			if (current == 2) {
				this.loadend =false
				this.recordList = []
				this.type = '2'
				this.getBrokeragelList();
			}


		}
	}
}
</script>

<style scoped lang="scss">
.integral-details .header {
	background-image: url('');
	background-repeat: no-repeat;
	background-size: 100% 218rpx;
	background-position: center bottom;
	width: 100%;
	height: 460rpx;
	font-size: 72rpx;
	color: #fff;
	padding: 31rpx 0 45rpx 0;
	box-sizing: border-box;
	text-align: center;
	font-family: 'Guildford Pro';
	@include main_bg_color(theme);
}

.integral-details .header .currentScore {
	font-size: 26rpx;
	color: rgba(255, 255, 255, 0.8);
	text-align: center;
	margin-bottom: 11rpx;
}

.integral-details .header .scoreNum {
	font-family: "Guildford Pro";
}

.integral-details .header .line {
	width: 60rpx;
	height: 3rpx;
	background-color: #fff;
	margin: 20rpx auto 0 auto;
}

.integral-details .header .nav {
	font-size: 22rpx;
	color: rgba(255, 255, 255, 0.8);
	flex: 1;
	margin-top: 35rpx;
}

.integral-details .header .nav .item {
	width: 33.33%;
	text-align: center;
}

.integral-details .header .nav .item .num {
	color: #fff;
	font-size: 40rpx;
	margin-bottom: 5rpx;
	font-family: 'Guildford Pro';
}

.integral-details .wrapper .nav {
	flex: 1;
	width: 690rpx;
	border-radius: 20rpx 20rpx 0 0;
	margin: -96rpx auto 0 auto;
	background-color: #f7f7f7;
	height: 96rpx;
	font-size: 30rpx;
	color: #bbb;
}

.integral-details .wrapper .nav .item {
	text-align: center;
	width: 33.3%;
}

.integral-details .wrapper .nav .item.on {
	background-color: #fff;
	@include main-color(theme);
	font-weight: bold;
	border-radius: 20rpx 0 0 0;
}

.integral-details .wrapper .nav .item:nth-of-type(2).on {
	border-radius: 0 20rpx 0 0;
}

.integral-details .wrapper .nav .item .iconfont {
	font-size: 38rpx;
	margin-right: 10rpx;
}

.integral-details .wrapper .list {
	background-color: #fff;
	padding: 24rpx 30rpx;
}

.integral-details .wrapper .list .tip {
	font-size: 25rpx;
	width: 690rpx;
	height: 60rpx;
	border-radius: 50rpx;
	background-color: #fff5e2;
	border: 1rpx solid #ffeac1;
	color: #c8a86b;
	padding: 0 20rpx;
	box-sizing: border-box;
	margin-bottom: 24rpx;
}

.integral-details .wrapper .list .tip .iconfont {
	font-size: 35rpx;
	margin-right: 15rpx;
}

.integral-details .wrapper .list .item {
	height: 124rpx;
	border-bottom: 1rpx solid #eee;
	font-size: 24rpx;
	color: #999;
}

.integral-details .wrapper .list .item .state {
	font-size: 28rpx;
	color: #282828;
	margin-bottom: 8rpx;
}

.integral-details .wrapper .list .item .num {
	font-size: 36rpx;
	font-family: 'Guildford Pro';
}

.integral-details .wrapper .list2 {
	background-color: #fff;
	padding: 24rpx 0;
}

.integral-details .wrapper .list2 .item {
	background-image: linear-gradient(to right, #fff7e7 0%, #fffdf9 100%);
	width: 690rpx;
	height: 180rpx;
	position: relative;
	border-radius: 10rpx;
	margin: 0 auto 20rpx auto;
	padding: 0 25rpx 0 180rpx;
	box-sizing: border-box;
}

.integral-details .wrapper .list2 .item .pictrue {
	width: 90rpx;
	height: 150rpx;
	position: absolute;
	bottom: 0;
	left: 45rpx;
}

.integral-details .wrapper .list2 .item .pictrue image {
	width: 100%;
	height: 100%;
}

.integral-details .wrapper .list2 .item .name {
	width: 285rpx;
	font-size: 30rpx;
	font-weight: bold;
	color: #c8a86b;
}

.integral-details .wrapper .list2 .item .earn {
	font-size: 26rpx;
	color: #c8a86b;
	border: 2rpx solid #c8a86b;
	text-align: center;
	line-height: 52rpx;
	height: 52rpx;
	width: 160rpx;
	border-radius: 50rpx;
}

.font_color {
	@include price_color(theme);
}

.noCart {
	margin-top: -62rpx;
	padding-top: 0.1rpx;
	height: 800rpx;
}

.noCart .pictrue {
	width: 414rpx;
	height: 336rpx;
	margin: 78rpx auto 56rpx auto;
}

.noCart .pictrue image {
	width: 100%;
	height: 100%;
}

.default_txt {
	font-size: 26rpx;
	color: #999;
	text-align: center;
}

.list {
	min-height: 72vh;
}
</style>